package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.FirewallRule;
import com.ruoyi.experiment.service.IFirewallRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 防火墙规则Controller
 * 
 * @author 邓鑫
 * @date 2023-07-28
 */
@RestController
@RequestMapping("/experiment/rule")
public class FirewallRuleController extends BaseController
{
    @Autowired
    private IFirewallRuleService firewallRuleService;

    /**
     * 查询防火墙规则列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(FirewallRule firewallRule)
    {
        startPage();
        List<FirewallRule> list = firewallRuleService.selectFirewallRuleList(firewallRule);
        return getDataTable(list);
    }

    /**
     * 导出防火墙规则列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:rule:export')")
    @Log(title = "防火墙规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirewallRule firewallRule)
    {
        List<FirewallRule> list = firewallRuleService.selectFirewallRuleList(firewallRule);
        ExcelUtil<FirewallRule> util = new ExcelUtil<FirewallRule>(FirewallRule.class);
        util.exportExcel(response, list, "防火墙规则数据");
    }

    /**
     * 获取防火墙规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:rule:query')")
    @GetMapping(value = "/{firewallRuleId}")
    public AjaxResult getInfo(@PathVariable("firewallRuleId") Long firewallRuleId)
    {
        return success(firewallRuleService.selectFirewallRuleByFirewallRuleId(firewallRuleId));
    }

    /**
     * 新增防火墙规则
     */
    @PreAuthorize("@ss.hasPermi('experiment:rule:add')")
    @Log(title = "防火墙规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirewallRule firewallRule)
    {
        return toAjax(firewallRuleService.insertFirewallRule(firewallRule));
    }

    /**
     * 修改防火墙规则
     */
    @PreAuthorize("@ss.hasPermi('experiment:rule:edit')")
    @Log(title = "防火墙规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirewallRule firewallRule)
    {
        return toAjax(firewallRuleService.updateFirewallRule(firewallRule));
    }

    /**
     * 删除防火墙规则
     */
    @PreAuthorize("@ss.hasPermi('experiment:rule:remove')")
    @Log(title = "防火墙规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{firewallRuleIds}")
    public AjaxResult remove(@PathVariable Long[] firewallRuleIds)
    {
        return toAjax(firewallRuleService.deleteFirewallRuleByFirewallRuleIds(firewallRuleIds));
    }

    /**
     * 策略查询防火墙规则列表 不带参数
     */
    @GetMapping("/getList")
    public AjaxResult getList()
    {
        return AjaxResult.success(firewallRuleService.getList());
    }
}
